require File.dirname(__FILE__)+ '/../zddi'

PATH=File.dirname(__FILE__).gsub("/", "\\")
class TEST_DNS

	CDNS_ACL = ZDDI::DNS::ACL.new
	CDNS_VIEW = ZDDI::DNS::VIEW.new
	CDNS_ZONE = ZDDI::DNS::ZONE.new
    CDNS_DOMAIN = ZDDI::DNS::DOMAIN.new
    CDNS_SHARERR = ZDDI::DNS::SHARERR.new
    CDNS_SEARCH = ZDDI::DNS::SEARCH.new
    CDNS_SYNCDATA = ZDDI::DNS::SYNCDATA.new
    LOW_NUM = 1
    HIGH_NUM = 5
    MASTER_DEVICE = "local.master"
    SLAVE_DEVICE = "test.9.16"
    THIRD_DEVICE = "test.9.24"
	
	def test_create_acl
        r = []
	 	r.push(CDNS_ACL.create_acl(:acl_name=>"shanghai", :acl_list=>["203.119.80.160", "20.1.1.0/24", "200.159.0.0/16"], :acl_comments=>"test"))
	 	return r
    end
	def test_create_all_acl
	 	r = test_create_acl
	 	r.push(CDNS_ACL.create_acl(:acl_name=>"beijing", :acl_comments=>"test", :filename=>PATH + "\\upload\\acl\\acl1.txt"))
	 	r.push(CDNS_ACL.create_acl(:acl_name=>"nanjing", :acl_comments=>"test", :filename=>PATH + "\\upload\\acl\\acl2.txt"))
	 	return r
	end
	def test_edit_acl
        r = []
		r.push(CDNS_ACL.edit_acl(:acl_name=>"shanghai", :del_ip=>["20.1.1.0/24"], :add_ip=>["20.1.4.0/24"], :acl_comments=>"edit"))
		return r
	end
	
	def test_del_acl
		r = []
		r.push(CDNS_ACL.del_acl(["shanghai"]))
		return r
	end
	def test_del_all_acl
		r = []
		r.push(CDNS_ACL.del_acl(["shanghai", "beijing", "nanjing"]))
		return r
	end
	
	def test_create_view
		r = []
		r.push(CDNS_VIEW.create_view(:view_name=>"test", :owner_list=>[MASTER_DEVICE, SLAVE_DEVICE, THIRD_DEVICE], :acl_list=>["shanghai"], :dns64_list=>["2003:20::/96", "abcd:1234:4567::/96"]))
		return r
	end
    def test_create_all_view
        r = test_create_view
        for i in LOW_NUM..HIGH_NUM do
		    r.push(CDNS_VIEW.create_view(:view_name=>"autoview%d" % i, :owner_list=>[MASTER_DEVICE, SLAVE_DEVICE], :acl_list=>['beijing'], :dns64_list=>["2000::/96"]))
        end
        return r
    end
	
	def test_edit_view
		r = []
		r.push(CDNS_VIEW.edit_view(:view_name=>"test", :del_acl=>[""], :add_acl=>["shanghai"], :dns64_list=>["2003:2004::/96", "ABD:2300::/96"]))
		return r
	end
	def test_modify_view
		r = []
		r.push(CDNS_VIEW.modify_view(:view_name=>"test", :owner_list=>[SLAVE_DEVICE]))
		return r
	end
	
	def test_del_view
		r = []
		r.push(CDNS_VIEW.del_view(["test"]))
		return r
	end
    def test_del_all_view
		r = test_del_view
        for i in LOW_NUM..HIGH_NUM do
		    r.push(CDNS_VIEW.del_view(["autoview%d" % i]))
        end
		return r
    end

    def test_create_zone
        r= []
        r.push(CDNS_ZONE.create_zone(:view_name=>"test", :owner=>[MASTER_DEVICE, SLAVE_DEVICE, THIRD_DEVICE], :zone_name=>"defaultzone"))
        r.push(CDNS_SYNCDATA.compare_zone_data(:server_list=>['203.119.80.40', '202.173.9.16', "202.173.9.24"], :domain_name=>"defaultzone", :rtype=>"SOA", :port=>"9393"))
        return r
    end
    def test_create_all_zone
        r = test_create_zone
        for i in LOW_NUM..HIGH_NUM do
            r.push(CDNS_ZONE.create_zone(:view_name=>"test", :owner=>[MASTER_DEVICE, SLAVE_DEVICE], :zone_name=>"autozone%d" % i))
        end
        return r
    end
    def test_create_zone_from_file
        r= []
        r.push(CDNS_ZONE.create_zone_from_file(:view_name=>"test", :owner=>[MASTER_DEVICE, SLAVE_DEVICE, THIRD_DEVICE],:zone_name=>"z1.com", :zone_file=>PATH + "\\upload\\zone\\z1.com.txt"))
        r.push(CDNS_SYNCDATA.compare_zone_data(:server_list=>['203.119.80.40', '202.173.9.16', "202.173.9.24"], :domain_name=>"defaultzone", :rtype=>"SOA", :port=>"9393"))
        #r.push(CDNS_ZONE.create_zone_from_file(:view_name=>"test", :owner=>[MASTER_DEVICE, SLAVE_DEVICE],:zone_name=>"z6.com", :zone_file=>PATH + "\\upload\\zone\\z6.com.txt"))
        #r.push(CDNS_ZONE.create_zone_from_file(:view_name=>"default", :owner=>[MASTER_DEVICE, SLAVE_DEVICE],:zone_name=>"z10.com", :zone_file=>PATH + "\\upload\\zone\\z10.com.txt"))
        return r
    end
    def test_create_zone_from_copy
        r= []
        r.push(CDNS_ZONE.create_zone_from_copy(:dst_view=>"test", :owner=>[MASTER_DEVICE], :src_view=>"default", :zone_name=>"z10.com"))
        r.push(CDNS_ZONE.create_zone_from_copy(:dst_view=>"default", :owner=>[MASTER_DEVICE, SLAVE_DEVICE], :src_view=>"test", :zone_name=>"mytest.com"))
        r.push(CDNS_ZONE.create_zone_from_copy(:dst_view=>"default", :owner=>[MASTER_DEVICE, SLAVE_DEVICE], :src_view=>"test", :zone_name=>"z1.com"))
        return r
    end
    def test_del_all_zone
        r= []
        r.push(CDNS_ZONE.delete_zone(:view_name=>"test", :zone_list=>["z1.com", "defaultzone", "z10.com", "z6.com"]))
        r.push(CDNS_ZONE.delete_zone(:view_name=>"default", :zone_list=>["z10.com", "mytest.com", "z1.com"]))
        return r
    end
    def test_modify_zone
        r= []
        r.push(CDNS_ZONE.modify_zone(:view_name=>"test", :zone_name=>"mytest.com", :owner_list=>[SLAVE_DEVICE]))
        return r
    end
    def test_del_zone
        r= []
        r.push(CDNS_ZONE.delete_zone(:view_name=>"test", :zone_list=>["defaultzone", "z1.com"]))
        return r
    end
    def test_create_domain
        r = []
        r.push(CDNS_DOMAIN.create_domain(:view_name=>"test", :zone_name=>"defaultzone", :domain_list=>[{"rname"=>"www1", "rtype"=>"A", "rdata"=>"8.8.8.8", "ttl"=>"3600"}]))
        r.push(CDNS_SYNCDATA.compare_zone_data(:server_list=>['203.119.80.40', '202.173.9.16', "202.173.9.24"], :domain_name=>"www1.defaultzone", :rtype=>"A", :port=>"9393"))
        r.push(CDNS_DOMAIN.create_domain(:view_name=>"test", :zone_name=>"defaultzone", :domain_list=>[{"rname"=>"batchwww1", "rtype"=>"A", "rdata"=>"7.7.7.7", "ttl"=>"5400"}]))
        #r.push(CDNS_DOMAIN.create_domain(:view_name=>"test", :zone_name=>"defaultzone", :domain_list=>[{"rname"=>"update", "rtype"=>"A", "rdata"=>"18.18.18.18", "ttl"=>"3600"}]))
        #r.push(CDNS_DOMAIN.create_domain(:view_name=>"test", :zone_name=>"defaultzone", :domain_list=>[{"rname"=>"ns2", "rtype"=>"NS", "rdata"=>"www.baidu.com.", "ttl"=>"3600"}]))
        r.push(CDNS_DOMAIN.create_domain(:view_name=>"test", :zone_name=>"defaultzone", :domain_list=>[{"rname"=>"aaaa", "rtype"=>"AAAA", "rdata"=>"1234:5678:90AB::CD", "ttl"=>"3600"}]))
        r.push(CDNS_SYNCDATA.compare_zone_data(:server_list=>['203.119.80.40', '202.173.9.16', "202.173.9.24"], :domain_name=>"aaaa.defaultzone", :rtype=>"AAAA", :port=>"9393"))
        #r.push(CDNS_DOMAIN.create_domain(:view_name=>"test", :zone_name=>"defaultzone", :domain_list=>[{"rname"=>"www2", "rtype"=>"A", "rdata"=>"8.8.8.8", "ttl"=>"3600"}]))
        r.push(CDNS_DOMAIN.create_domain(:view_name=>"test", :zone_name=>"defaultzone", :domain_list=>[{"rname"=>"mx", "rtype"=>"MX", "rdata"=>"10 www.baidu.com.", "ttl"=>"3600"}]))
        r.push(CDNS_SYNCDATA.compare_zone_data(:server_list=>['203.119.80.40', '202.173.9.16', "202.173.9.24"], :domain_name=>"defaultzone", :rtype=>"SOA", :port=>"9393"))
        #r.push(CDNS_DOMAIN.create_domain(:view_name=>"test", :zone_name=>"defaultzone", :domain_list=>[{"rname"=>"srv", "rtype"=>"SRV", "rdata"=>"12 14 80 www.movie12.edu.", "ttl"=>"3600"}]))
        #r.push(CDNS_DOMAIN.create_domain(:view_name=>"test", :zone_name=>"defaultzone", :domain_list=>[{"rname"=>"cname", "rtype"=>"CNAME", "rdata"=>"cname.baidu.com.", "ttl"=>"3600"}]))
        #r.push(CDNS_DOMAIN.create_domain(:view_name=>"test", :zone_name=>"defaultzone", :domain_list=>[{"rname"=>"0.0.127", "rtype"=>"PTR", "rdata"=>"www.defaultzone.", "ttl"=>"3600"}]))
        #r.push(CDNS_DOMAIN.create_domain(:view_name=>"test", :zone_name=>"defaultzone", :domain_list=>[{"rname"=>"txt", "rtype"=>"TXT", "rdata"=>"txt::125@#", "ttl"=>"3600"}]))
        #r.push(CDNS_DOMAIN.create_domain(:view_name=>"test", :zone_name=>"defaultzone", :domain_list=>[{"rname"=>"naptr", "rtype"=>"NAPTR", "rdata"=>"18 35 Au siip+E2000U !^.*$!simmmp:information@cnnic.cn! mb", "ttl"=>"3600"}]))
        return r
    end 
    def test_create_batch_domain
        r = []
        r.push(CDNS_DOMAIN.create_batch_domain(:view_name=>"test",:zone_name=>"defaultzone", :file_name=>PATH + "\\upload\\zone\\batch_domain.txt", :example_domain=>["batch1.defaultzone", "batch2.defaultzone"]))
        return r
    end 
    def test_del_domain
        r = []
        r.push(CDNS_DOMAIN.del_domain(:view_name=>"test", :zone_name=>"defaultzone", :domain_list=>["www1.defaultzone", "www2.defaultzone", "txt.defaultzone", "cname.defaultzone", "srv.defaultzone", "ns2.defaultzone", "mx.defaultzone", "aaaa.defaultzone"]))
        return r
    end
    def test_edit_domain
        r = []
        r.push(CDNS_DOMAIN.edit_domain(:view_name=>"test", :zone_name=>"defaultzone", :domain_list=>[{"rname"=>"update", "rtype"=>"A", "rdata"=>"9.9.9.9", "ttl"=>"7200"}]))
        return r
    end
    def test_edit_batch_domain
        r = []
        r.push(CDNS_DOMAIN.edit_batch_domain(:view_name=>"test", :zone_name=>"defaultzone", :domain_list=>[{"rname"=>"www1", "rtype"=>"A", "rdata"=>"9.9.9.9", "ttl"=>"7200"}, {"rname"=>"batchwww1", "rtype"=>"A", "rdata"=>"9.9.9.9", "ttl"=>"7200"}]))
        return r
    end
    def test_create_share_rr
        r = []
        r.push(CDNS_SHARERR.create_share_rr(:domain_list=>[{"rname"=>"share", "rtype"=>"A", "rdata"=>"6.6.6.6", "ttl"=>"3600"}], :share_owner=>["default.z10.com", "test.z1.com"]))
        return r
    end
    def test_edit_share_rr
        r = []
        r.push(CDNS_SHARERR.edit_share_rr(:domain_list=>[{"rname"=>"share", "rtype"=>"A", "rdata"=>"9.9.9.9", "ttl"=>"3600"}], :share_owner=>["default.z10.com", "test.z1.com"]))
        return r
    end
    def test_modify_share_rr
        r = []
        r.push(CDNS_SHARERR.modify_share_rr(:share_rr_list=>["share"], :add_owner=>["test.z10.com"]))
        return r
    end
    def test_del_share_rr
        r = []
        r.push(CDNS_SHARERR.del_share_rr(:domain_list=>[{"rname"=>"share", "rtype"=>"A", "rdata"=>"9.9.9.9", "ttl"=>"3600"}], :share_owner=>["default.z10.com", "test.z1.com"]))
        return r
    end
    def test_search_domain
        r = []
        r.push(CDNS_SEARCH.search_domain(:domain_name=>"ns1.z10.com", :doamin_num=>2))
        return r
    end       
    def test_search_domain_edit
        r = []
        r.push(CDNS_SEARCH.search_domain_edit(:domain_name=>"update.defaultzone", :ttl=>"9998", :rdata=>"2.2.2.2"))
        return r
    end
    def test_search_domain_batch_edit
        r = []
        r.push(CDNS_SEARCH.search_domain_batch_edit(:domain_name=>"ns1.z10.com", :ttl=>"9999", :rdata=>"127.0.0.1"))
        return r
    end
    def test_search_ip
        r = []
        r.push(CDNS_SEARCH.search_ip(:ip=>"8.8.8.8", :ip_num=>2))
        return r
    end       
    def test_search_ip_batch_edit
        r = []
        r.push(CDNS_SEARCH.search_ip_batch_edit(:ip=>"127.0.0.1", :ttl=>"9999", :rdata=>"203.119.80.40"))
        return r
    end
    def test_defaultzone
        r = []
        r.push(CDNS_SYNCDATA.defaultzone(:owner=>[MASTER_DEVICE, SLAVE_DEVICE, THIRD_DEVICE], :view_name=>"test", :zone_name=>"defaultzone"))
        r.push(CDNS_SYNCDATA.compare_zone_data(:server_list=>['203.119.80.40', '202.173.9.16', "202.173.9.24"], :domain_name=>"defaultzone", :rtype=>"SOA", :port=>"9393"))
        return r
    end
    def test_defaultzone_by_stop_service
        r = []
        r.push(CDNS_SYNCDATA.defaultzone(:owner=>[MASTER_DEVICE], :stop_owner=>SLAVE_DEVICE, :view_name=>"test", :domain_name=>"defaultzone", :rtype=>"SOA"))
        return r
    end
end	
